import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router);
/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/index',
    component: Layout,
    redirect: '/home',
    children: [{
      path: '/home',
      name: '首页',
      component: () => import('@/views/Index/Index'),
      meta: { title: '首页', icon: 'index' }
    }]
  },
  {
    path: '/usermanagement',
    component: Layout,
    redirect: '/usermanagement',
    name: 'usermanagement',
    meta: { title: '代理推荐注册用户', icon: 'admin' },
    children: [
      {
        path: '/usersetting',
        name: 'usersetting',
        component: () => import('@/views/userManagement/UserSetting'),
        meta: { title: '代理推荐注册用户'}
      }
    ]
  },
  {
    path: '/giftManagement',
    component: Layout,
    redirect: '/giftManagement',
    name: 'giftManagement',
    meta: { title: '关联用户管理', icon: 'book' },
    children: [{
      path: '/giftList',
      name: '绑定用户',
      component: () => import('@/views/giftManagement/GiftList'),
      meta: { title: '绑定用户'}
    }]
  },
  {
    path: '/orderManagement',
    component: Layout,
    redirect: '/orderManagement',
    name: 'orderManagement',
    meta: { title: '订单管理', icon: 'book' },
    children: [
      {
        path: '/recordOrder',
        name: '订单记录',
        component: () => import('@/views/orderManagement/RecordOrder'),
        meta: { title: '订单记录'}
      }
    ]
  },
  {
    path: '/userFlowRecord',
    component: Layout,
    redirect: '/userFlowRecord',
    name: 'userFlowRecord',
    meta: { title: '代理分润', icon: 'book' },
    children: [
      {
        path: '/memberVipRecord',
        name: '充值分润',
        component: () => import('@/views/userFlowRecord/MemberVipRecord'),
        meta: { title: '充值分润'}
      },
      {
        path: '/goldChangeRecord',
        name: '礼物分润',
        component: () => import('@/views/userFlowRecord/GoldChangeRecord'),
        meta: { title: '礼物分润'}
      },
      {
        path: '/goldNumRecord',
        name: '金币消费分润',
        component: () => import('@/views/userFlowRecord/GoldNumRecord'),
        meta: { title: '金币消费分润'}
      },
      {
        path: '/rechargeProfitList',
        name: '分润统计',
        component: () => import('@/views/userFlowRecord/rechargeProfitList'),
        meta: { title: '分润统计'}
      }
    ]
  },
  {
    path: '/systemManagement',
    component: Layout,
    redirect: '/systemManagement',
    name: 'systemManagement',
    meta: { title: '系统管理', icon: 'setting' },
    children: [
      {
        path: '/modifyLoginPassword',
        name: 'modifyLoginPassword',
        component: () => import('@/views/systemManagement/ModifyLoginPassword'),
        meta: { title: '修改登录密码'}
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
]

const createRouter = () => new Router({
  // mode: 'history', // 需要后端服务支持
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter();
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher // reset router
}

export default router
